/*
 * Copyright Exafunction, Inc.
 */

package com.codeium.intellij

import exa.codeium_common_pb.CodeiumCommon

// Map from IntelliJ language ID to Codeium language.
val LanguageMap =
    mapOf(
        "Blade" to CodeiumCommon.Language.LANGUAGE_BLADE,
        "C++" to CodeiumCommon.Language.LANGUAGE_C,
        "CMake" to CodeiumCommon.Language.LANGUAGE_CMAKE,
        "CoffeeScript" to CodeiumCommon.Language.LANGUAGE_COFFEESCRIPT,
        "C++" to CodeiumCommon.Language.LANGUAGE_CPP,
        "C#" to CodeiumCommon.Language.LANGUAGE_CSHARP,
        "CSS" to CodeiumCommon.Language.LANGUAGE_CSS,
        "Dart" to CodeiumCommon.Language.LANGUAGE_DART,
        "Dockerfile" to CodeiumCommon.Language.LANGUAGE_DOCKERFILE,
        "Elixir" to CodeiumCommon.Language.LANGUAGE_ELIXIR,
        "go" to CodeiumCommon.Language.LANGUAGE_GO,
        "Groovy" to CodeiumCommon.Language.LANGUAGE_GROOVY,
        "Handlebars" to CodeiumCommon.Language.LANGUAGE_HANDLEBARS,
        "HCL" to CodeiumCommon.Language.LANGUAGE_HCL,
        "HTML" to CodeiumCommon.Language.LANGUAGE_HTML,
        "Ini" to CodeiumCommon.Language.LANGUAGE_INI,
        "JAVA" to CodeiumCommon.Language.LANGUAGE_JAVA,
        "JavaScript JSX" to CodeiumCommon.Language.LANGUAGE_JAVASCRIPT,
        "JavaScript" to CodeiumCommon.Language.LANGUAGE_JAVASCRIPT,
        "ECMA Script Level 4" to CodeiumCommon.Language.LANGUAGE_JAVASCRIPT,
        "ECMAScript 6" to CodeiumCommon.Language.LANGUAGE_JAVASCRIPT,
        "JSON" to CodeiumCommon.Language.LANGUAGE_JSON,
        "JSON5" to CodeiumCommon.Language.LANGUAGE_JSON,
        "kotlin" to CodeiumCommon.Language.LANGUAGE_KOTLIN,
        "Latex" to CodeiumCommon.Language.LANGUAGE_LATEX,
        "LESS" to CodeiumCommon.Language.LANGUAGE_LESS,
        "Lua" to CodeiumCommon.Language.LANGUAGE_LUA,
        "Makefile" to CodeiumCommon.Language.LANGUAGE_MAKEFILE,
        "Markdown" to CodeiumCommon.Language.LANGUAGE_MARKDOWN,
        "ObjectiveC" to CodeiumCommon.Language.LANGUAGE_OBJECTIVEC,
        "protobuf" to CodeiumCommon.Language.LANGUAGE_PBTXT,
        "Perl5" to CodeiumCommon.Language.LANGUAGE_PERL,
        "PHP" to CodeiumCommon.Language.LANGUAGE_PHP,
        "PowerShell" to CodeiumCommon.Language.LANGUAGE_POWERSHELL,
        "protobuf" to CodeiumCommon.Language.LANGUAGE_PROTOBUF,
        "Python" to CodeiumCommon.Language.LANGUAGE_PYTHON,
        "python" to CodeiumCommon.Language.LANGUAGE_PYTHON,
        "R" to CodeiumCommon.Language.LANGUAGE_R,
        "ruby" to CodeiumCommon.Language.LANGUAGE_RUBY,
        "Rust" to CodeiumCommon.Language.LANGUAGE_RUST,
        "Scala" to CodeiumCommon.Language.LANGUAGE_SCALA,
        "Scala 3" to CodeiumCommon.Language.LANGUAGE_SCALA,
        "Scala 3 Worksheet" to CodeiumCommon.Language.LANGUAGE_SCALA,
        "SCSS" to CodeiumCommon.Language.LANGUAGE_SCSS,
        "Shell Script" to CodeiumCommon.Language.LANGUAGE_SHELL,
        "Solidity" to CodeiumCommon.Language.LANGUAGE_SOLIDITY,
        "SQL" to CodeiumCommon.Language.LANGUAGE_SQL,
        "SQLite" to CodeiumCommon.Language.LANGUAGE_SQL,
        "DBN-SQL" to CodeiumCommon.Language.LANGUAGE_SQL,
        "GenericSQL" to CodeiumCommon.Language.LANGUAGE_SQL,
        "MySQL" to CodeiumCommon.Language.LANGUAGE_SQL,
        "OracleSqlPlus" to CodeiumCommon.Language.LANGUAGE_SQL,
        "PostgreSQL" to CodeiumCommon.Language.LANGUAGE_SQL,
        "SvelteHTML" to CodeiumCommon.Language.LANGUAGE_SVELTE,
        "Swift" to CodeiumCommon.Language.LANGUAGE_SWIFT,
        "swift" to CodeiumCommon.Language.LANGUAGE_SWIFT,
        "TOML" to CodeiumCommon.Language.LANGUAGE_TOML,
        "TypeScript JSX" to CodeiumCommon.Language.LANGUAGE_TSX,
        "TypeScript" to CodeiumCommon.Language.LANGUAGE_TYPESCRIPT,
        "Vue" to CodeiumCommon.Language.LANGUAGE_VUE,
        "XML" to CodeiumCommon.Language.LANGUAGE_XML,
        "yaml" to CodeiumCommon.Language.LANGUAGE_YAML,
    )

val SupportedLanguages =
    setOf(
        CodeiumCommon.Language.LANGUAGE_APL,
        CodeiumCommon.Language.LANGUAGE_ASSEMBLY,
        CodeiumCommon.Language.LANGUAGE_ASTRO,
        CodeiumCommon.Language.LANGUAGE_BLADE,
        CodeiumCommon.Language.LANGUAGE_C,
        CodeiumCommon.Language.LANGUAGE_CLOJURE,
        CodeiumCommon.Language.LANGUAGE_CMAKE,
        CodeiumCommon.Language.LANGUAGE_COBOL,
        CodeiumCommon.Language.LANGUAGE_COFFEESCRIPT, // Adjacent to Codeium language (JS)
        CodeiumCommon.Language.LANGUAGE_CPP,
        CodeiumCommon.Language.LANGUAGE_CSHARP,
        CodeiumCommon.Language.LANGUAGE_CRYSTAL,
        CodeiumCommon.Language.LANGUAGE_CSS,
        CodeiumCommon.Language.LANGUAGE_CUDACPP,
        CodeiumCommon.Language.LANGUAGE_DART,
        CodeiumCommon.Language.LANGUAGE_DOCKERFILE,
        CodeiumCommon.Language.LANGUAGE_ELIXIR,
        CodeiumCommon.Language.LANGUAGE_FORTRAN,
        CodeiumCommon.Language.LANGUAGE_FREEFORM,
        CodeiumCommon.Language.LANGUAGE_FSHARP,
        CodeiumCommon.Language.LANGUAGE_GDSCRIPT,
        CodeiumCommon.Language.LANGUAGE_GO,
        CodeiumCommon.Language.LANGUAGE_GRADLE,
        CodeiumCommon.Language.LANGUAGE_GROOVY,
        CodeiumCommon.Language.LANGUAGE_HANDLEBARS,
        CodeiumCommon.Language.LANGUAGE_HASKELL,
        CodeiumCommon.Language.LANGUAGE_HCL,
        CodeiumCommon.Language.LANGUAGE_HTML,
        CodeiumCommon.Language.LANGUAGE_INI,
        CodeiumCommon.Language.LANGUAGE_JAVA,
        CodeiumCommon.Language.LANGUAGE_JAVASCRIPT,
        CodeiumCommon.Language.LANGUAGE_JSON,
        CodeiumCommon.Language.LANGUAGE_JULIA,
        CodeiumCommon.Language.LANGUAGE_KOTLIN,
        CodeiumCommon.Language.LANGUAGE_LATEX,
        CodeiumCommon.Language.LANGUAGE_LESS, // Adjacent to Codegen language (JS)
        CodeiumCommon.Language.LANGUAGE_LISP,
        CodeiumCommon.Language.LANGUAGE_LUA,
        CodeiumCommon.Language.LANGUAGE_M68KASSEMBLY,
        CodeiumCommon.Language.LANGUAGE_MAKEFILE,
        CodeiumCommon.Language.LANGUAGE_MATLAB,
        CodeiumCommon.Language.LANGUAGE_MUMPS,
        CodeiumCommon.Language.LANGUAGE_NIM,
        CodeiumCommon.Language.LANGUAGE_OBJECTIVEC,
        CodeiumCommon.Language.LANGUAGE_OBJECTIVECPP,
        CodeiumCommon.Language.LANGUAGE_OCAML,
        CodeiumCommon.Language.LANGUAGE_PASCAL,
        CodeiumCommon.Language.LANGUAGE_PBTXT, // Empirically okay
        CodeiumCommon.Language.LANGUAGE_PERL,
        CodeiumCommon.Language.LANGUAGE_PHP,
        CodeiumCommon.Language.LANGUAGE_POWERSHELL,
        CodeiumCommon.Language.LANGUAGE_PROLOG,
        CodeiumCommon.Language.LANGUAGE_PROTOBUF, // Empirically okay
        CodeiumCommon.Language.LANGUAGE_PYTHON,
        CodeiumCommon.Language.LANGUAGE_R,
        CodeiumCommon.Language.LANGUAGE_RUBY,
        CodeiumCommon.Language.LANGUAGE_RUST,
        CodeiumCommon.Language.LANGUAGE_SAS,
        CodeiumCommon.Language.LANGUAGE_SASS, // Adjacent to Codegen language (JS)
        CodeiumCommon.Language.LANGUAGE_SCALA,
        CodeiumCommon.Language.LANGUAGE_SCSS,
        CodeiumCommon.Language.LANGUAGE_SHELL,
        CodeiumCommon.Language.LANGUAGE_SOLIDITY,
        CodeiumCommon.Language.LANGUAGE_SQL,
        CodeiumCommon.Language.LANGUAGE_STARLARK,
        CodeiumCommon.Language.LANGUAGE_SVELTE,
        CodeiumCommon.Language.LANGUAGE_SWIFT,
        CodeiumCommon.Language.LANGUAGE_TOML,
        CodeiumCommon.Language.LANGUAGE_TSX,
        CodeiumCommon.Language.LANGUAGE_TYPESCRIPT,
        CodeiumCommon.Language.LANGUAGE_UNIXASSEMBLY,
        CodeiumCommon.Language.LANGUAGE_VISUALBASIC,
        CodeiumCommon.Language.LANGUAGE_VUE,
        CodeiumCommon.Language.LANGUAGE_WEBASSEMBLY,
        CodeiumCommon.Language.LANGUAGE_YAML,
    )

fun getLanguage(language: String): CodeiumCommon.Language {
  return LanguageMap[language] ?: CodeiumCommon.Language.LANGUAGE_UNSPECIFIED
}

fun isWellSupportedLanguage(language: String): Boolean {
  return language == "*" || SupportedLanguages.contains(getLanguage(language))
}
